package com.enba.boot.i18n.config;

import com.enba.boot.core.base.ShowBootInfo;
import com.enba.boot.i18n.I18nHelper;
import com.enba.boot.i18n.resolver.HeaderLocaleResolver;
import javax.annotation.PostConstruct;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.LocaleResolver;

@Configuration
public class I18nAutoConfiguration implements ShowBootInfo {

  @Bean
  public LocaleResolver headerLocaleResolver() {
    return new HeaderLocaleResolver();
  }

  @Bean
  public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("messages");
    return messageSource;
  }

  @Bean
  public I18nHelper i18nHelper(MessageSource messageSource) {
    return new I18nHelper(messageSource);
  }

  @PostConstruct
  @Override
  public void showBootInfo() {
    ShowBootInfo.moduleMap.put("enba-boot-starter-i18n", "enba-boot-starter-i18n模块集成成功");
  }
}
